#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int mod=1e9+7;

ll read(){
    char c;ll r;bool f=0;
    for(c=getchar();c>'9'||c<'0';c=getchar()) if(c=='-') f=1;
    for(r=0;c>='0'&&c<='9';c=getchar()) r=r*10+c-'0';
    if(f) return -r;
    else return r;
}

void print(const ll &x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

inline int add(const int &x,const int &y){return ((ll)x+y)%mod;}
inline int mul(const int &x,const int &y){return ((ll)x*y)%mod;}

int ten[40];
struct Status{
    int cnt,sum,sqr;
    inline Status(const int &cnt=0,const int &sum=0,const int &sqr=0):cnt(cnt),sum(sum),sqr(sqr){}
    inline Status apply(const int &coe,const int &exp) const{
        int app=mul(coe,ten[exp]);
        return Status(cnt,add(sum,mul(cnt,app)),add(add(sqr,mul(cnt,mul(app,app))),mul(2,mul(app,sum))));
    }
    inline Status operator + (const Status &s) const{return Status(add(cnt,s.cnt),add(sum,s.sum),add(sqr,s.sqr));}
};

Status _f[20][7][7];
bool vis[20][7][7];
int num[20];
Status f(int digits,int mosum,int moval,bool lim){
    if(digits<=0) if(mosum&&moval) return Status(1,0,0); else return Status(0,0,0);
    if(!lim&&vis[digits][mosum][moval]) return _f[digits][mosum][moval];

    int mx=lim?num[digits]:9;
    Status ans;
    for(int i=0;i<=mx;i++){
        if(i==7) continue;
        ans=ans+f(digits-1,(mosum+i)%7,(moval*10+i)%7,lim&&i==mx).apply(i,digits-1);
    }
    if(!lim) _f[digits][mosum][moval]=ans,vis[digits][mosum][moval]=1;
    return ans;
}

int solve(ll x){
    if(x<0) return 0;
    //printf("x=%I64d\n",x);
    int len=0;
    while(x) num[++len]=x%10,x/=10;
    return f(len,0,0,1).sqr;
}

int main(){
    ten[0]=1;
    for(int i=1;i<40;i++) ten[i]=mul(ten[i-1],10);

    int T;
    T=read();
    while(T--){
        ll x,y;
        x=read();y=read();
        int ans;
        ans=solve(y)-solve(x-1);
        if(ans<0) ans+=mod;
        printf("%d\n",ans);
    }
    return 0;
}
